package com.epin.business.commons.controller;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.epin.base.plugins.AbstractBean;
import com.epin.base.plugins.BaseController;
import com.epin.business.commons.dao.LoginInfoMapper;
import com.epin.business.commons.entity.LoginInfo;
import com.epin.business.commons.service.LoginInfoService;

/**
 * <p>
 *   前端控制器
 * </p>
 *
 * @author xj
 * @since 2017-01-04
 */
@Controller
@RequestMapping("/loginlog/")
public class LoginInfoController extends BaseController {

	@Autowired
	private LoginInfoService loginlogService;
	
	@Autowired
	private LoginInfoMapper loginlogMapper;
	
	@RequestMapping("listUI")
    public String listUI() {
		return "system/loginlog/list";
    }
	
	@GetMapping("load")
	@ResponseBody
    public Object load(int pageNumber, int pageSize, String keyword) {
		Map<String, Object> pageResponse = new HashMap<String, Object>();
		pageNumber = pageNumber <= 0 ? 1 : pageNumber;
		pageSize = pageSize <= 0 ? 10 : pageSize;
		Map<String, Object> parameter = new LinkedHashMap<String, Object>();
		parameter.put("keyword", keyword);
		Page<LoginInfo> list = loginlogService.selectToShowPage(new Page<LoginInfo>(pageNumber, pageSize), parameter);
		pageResponse.put("total", list.getTotal());
		pageResponse.put("rows",list.getRecords());
		return pageResponse;
    }
	
	
	@RequestMapping(value = "deleteBatch", method = RequestMethod.POST)
	@ResponseBody
    public AbstractBean delete() {	
		loginlogMapper.deleteByMap(null);
		return success();
    }	

}
